<template>
  <div class="content">
    <div class="content-main">
      <el-row :gutter="60">
        <el-col :span="18">
          <div class="left-content">
            <div class="left-content-title">
              <div class="title-name">{{ detailsData.title }}</div>
              <div class="list-info-time">
                <span>{{ detailsData.createTime }}</span>
              </div>
            </div>
            <div class="left-content-info" v-html="detailsData.articleContent"></div>
          </div>
        </el-col>
        <el-col :span="6">
          <div class="right-content">
            <h1>最新新闻</h1>
            <div class="list-info" v-for="(item, index) in listData.splice(0, 3)" :key="index">
              <div class="list-info-img">
                <img
                  :src="item.articlePicture"
                  alt=""
                  width="100%"
                  height="120px"
                  @click="navigateToNews(item.id)"
                />
                <div class="list-title">
                  <span>{{ item.title }}</span>
                </div>
              </div>
            </div>
          </div>
        </el-col>
      </el-row>
    </div>
  </div>
</template>
<script setup>
import { View } from '@element-plus/icons-vue'
import { cmsArticleDetail, cmsArticle } from '@/api'
import { useRoute, useRouter } from 'vue-router'
const route = useRoute()
const router = useRouter()
const detailsData = ref({})
const listData = ref([])

function navigateToNews(id) {
  router.push({ path: 'newsDetails', query: { id: id } })
  cmsArticleDetail({ id: id }).then((res) => {
    if (res.code == '0') {
      detailsData.value = res.data
    }
  })
}
function getDetail() {
  cmsArticleDetail({ id: route.query.id }).then((res) => {
    if (res.code == '0') {
      detailsData.value = res.data
    }
  })
  cmsArticle({
    articleType$Contains: 'NS' //科普知识
  }).then((res) => {
    if (res.code == '0') {
      listData.value = res.data.list
    }
  })
}
onMounted(() => {
  getDetail()
})
</script>
<style lang="scss" scoped>
.content {
  background-color: #f6faff;
  padding: 20px 0;
}

.content-main {
  width: 1200px;
  margin: auto;

  .left-content {
    width: 100%;
    padding: 20px;
    background-color: #fff;

    .left-content-title {
      margin-bottom: 20px;
      height: 100px;
      border-bottom: 1px solid #ebedf0;

      .list-info-time {
        text-align: center;
        font-size: 12px;
        padding: 20px 0;
        color: #8992a9;
      }

      .title-name {
        font-size: 22px;
        font-weight: bold;
        text-align: center;
      }
    }

    .left-content-info {
      min-height: 600px;
    }
  }

  .right-content {
    width: 100%;
    padding: 20px;
    background-color: #fff;

    h1 {
      margin: 0;
      font-size: 18px;
      font-weight: 500;
    }

    .list-info {
      margin: 15px 10px;

      .list-info-img {
        padding: 10px 20px 5px 20px;
        border: 1px solid #ebedf0;
        font-size: 13px;
        text-align: center;
      }

      .list-title {
        display: flex;
        align-items: center;
        justify-content: center;
        margin-top: 5px;
        padding-right: 30px;
        padding-left: 20px;
        cursor: pointer;
      }
    }
  }
}
</style>
